package guava;

import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import org.junit.Test;

import java.util.Arrays;

/**
 * @author dycong
 * @date 2018/3/30 8:51
 */
public class GuavaTest1 {

    @Test
    public void test() {
        Joiner joiner = Joiner.on(";").skipNulls();
        System.out.println(joiner.join("Harry", null, "Ron", "Hermione"));
        Joiner joiner2 = Joiner.on(";").useForNull("null");
        System.out.println(joiner2.join("Harry", null, "Ron", "Hermione"));
    }

    @Test
    public void test1() {
        String str = ",a,b, ab , ,,";
        Arrays.stream(str.split(",")).forEach(System.out::println);
        System.out.println("-----------");
        Iterable<String> iterable = Splitter.on(",").trimResults().omitEmptyStrings().split(str);
        iterable.forEach(System.out::println);
        String str2 = "removes all leading or trailing characters matching the given";
        Iterable<String> iterable2 = Splitter.fixedLength(5).split(str2);
        iterable2.forEach(System.out::println);

        Iterable<String> iterable3 = Splitter.fixedLength(5).trimResults().omitEmptyStrings().split(str2);
        iterable3.forEach(System.out::println);
    }

    @Test
    public void test2() {
        System.out.println(CharMatcher.JAVA_LETTER.matches('a'));
        System.out.println(CharMatcher.JAVA_UPPER_CASE.matches('a'));

    }

    @Test
    public void test3() {
        //http://ifeve.com/google-guava-newcollectiontypes/
        /**
         * 维基百科从数学角度这样定义Multiset：”集合[set]概念的延伸，它的元素可以重复出现…与集合[set]相同而与元组[tuple]相反的是，
         * Multiset元素的顺序是无关紧要的：Multiset {a, a, b}和{a, b, a}是相等的”。
         * ——译者注：这里所说的集合[set]是数学上的概念，Multiset继承自JDK中的Collection接口，而不是Set接口，所以包含重复元素并没有违反原有的接口契约。
         */
        Multiset<String> multiset = HashMultiset.create();
        multiset.add("1");
        multiset.add("1");
        multiset.add("1");
        multiset.add("1");
        multiset.add("1");
        multiset.add("1");
        multiset.add("1");
        multiset.add("1");
        System.out.println(multiset);
        System.out.println(multiset.count("1"));
        System.out.println(multiset.size());
        multiset.stream().forEach(System.out::println);

    }

    @Test
    public void test4() {


    }

    @Test
    public void test5() {


    }

    @Test
    public void test6() {


    }

    @Test
    public void test7() {


    }

    @Test
    public void test8() {


    }


}
